package com.cuz.hot100.elsepackage;

import com.cuz.hot100.datastruck.ListNode;

public class ReverseLinkedList {
    public static ListNode solution2(ListNode head) {
        if (head == null) {
            return null;
        }
        ListNode preHead = new ListNode();
        preHead.next = head;
        ListNode cur = head;
        ListNode post = cur.next;
        cur.next = null;
        cur = post;
        while (cur != null) {
            post = cur.next;
            cur.next = preHead.next;
            preHead.next = cur;
            cur = post;
        }
        return preHead.next;
    }
}
